package org.aeon.heroicsagatextedition.Input;

import java.util.Scanner;

/**
 * @projectName: HeroicSagaTextEdition
 * @package: org.aeon.heroicsagatextedition.utils
 * @className: ScannerUtil
 * @author: MissingAeon
 * @date: 2023/12/22 14:05
 * @description: 输入工具类
 */
public class ScannerUtil implements GameInput {
    private static final Scanner DEFAULT_SCANNER = new Scanner(System.in);

    public static Scanner getScanner() {
        return DEFAULT_SCANNER;
    }

    public String scanString() {
        String next = DEFAULT_SCANNER.next();
        DEFAULT_SCANNER.nextLine();
        return next;
    }

    public int scanInt() {
        while (true) {
            if (DEFAULT_SCANNER.hasNextInt()) {
                int nextInt = DEFAULT_SCANNER.nextInt();
                DEFAULT_SCANNER.nextLine();
                return nextInt;
            }
            DEFAULT_SCANNER.next();
            System.out.println("需要输入数字，请重新输入！");
        }
    }

    /**
     * 按回车键继续...
     */
    @Override
    public boolean pauseBeforeInput() {
        System.out.println("按回车键继续...");
        DEFAULT_SCANNER.nextLine(); // 等待用户按回车键
        return true;
    }
}
